package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.entity.Vehicle;
import cn.tedu.ivos.vehicle.service.VehicleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "车辆模块")
@Slf4j
@RequestMapping("/v1/vehicle")
@Validated
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    @Operation(summary = "车辆查询")
    @ApiOperationSupport(order = 10)
    @GetMapping("/select")
    public JsonResult selectVehicleBy(VehicleQuery vehicleQuery){
        log.debug("开始查询车辆：VehicleQuery={}"+vehicleQuery);
        List<Vehicle> vehicleList=vehicleService.selectVehicleBy(vehicleQuery);
        return JsonResult.ok(vehicleList);
    }

    @Operation(summary = "车辆保存")
    @ApiOperationSupport(order = 20)
    @PostMapping("/save")
    public JsonResult saveVehicle(@Validated VehicleSaveParam vehicleSaveParam){
        log.debug("开始保存车辆：VehicleSaveParam={}"+vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @Operation(summary = "车辆删除")
    @ApiOperationSupport(order = 30)
    @PostMapping("/delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("开始删除车辆：id={}"+id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @Operation(summary="车辆解绑")
    @ApiOperationSupport(order = 40)
    @PostMapping("/unbind/{vehicleId}")
    public JsonResult unBindVehicle(@PathVariable Long vehicleId){
        log.debug("解绑车辆id：vehicleId={}",vehicleId);
        vehicleService.unBindVehicle(vehicleId);
        return JsonResult.ok();
    }

    @Operation(summary = "车辆绑定")
    @ApiOperationSupport(order = 50)
    @PostMapping("/bind/{geofenceId}/{vehicleId}")
    public JsonResult bindVehicle(@PathVariable Long geofenceId,@PathVariable Long vehicleId){
        log.debug("绑定车辆id：vehicleId={},geofenceId={}",vehicleId,geofenceId);
        vehicleService.bindVehicle(geofenceId,vehicleId);
        return JsonResult.ok();
    }


}
